package com.hanyxx.coll;

import lombok.AllArgsConstructor;
import lombok.ToString;

import java.util.HashSet;
import java.util.Set;

/**
 * @author layman
 * @date 2021/2/25
 */
public class Demo03 {
    public static void main(String[] args) {
        Set<Person> set = new HashSet();
        Person p1 = new Person("钢铁侠",28);
        Person p2 = new Person("黑寡妇",28);
        Person p3 = new Person("黑寡妇",28);
        Person p4 = new Person("蜘蛛侠",18);
        set.add(p1);
        set.add(p2);
        set.add(p3);
        set.add(p4);
        System.out.println(set);
    }
}
@AllArgsConstructor
@ToString
class Person{
    private String name;
    private Integer age;

    /*@Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(name, person.name) &&
                Objects.equals(age, person.age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }*/
}
